package com.example.testapplication;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class IntentActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);
        // 获取电话图片按钮
        ImageButton imageButton = (ImageButton) findViewById(R.id.imageButton_phone);
        // 获取短信图片按钮
        ImageButton imageButton1 = (ImageButton) findViewById(R.id.imageButton_sms);
        imageButton.setOnClickListener(listener);
        imageButton1.setOnClickListener(listener);

    }
    // 创建监听事件对象
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(); // 创建Intent对象
            switch (view.getId()){
                case R.id.imageButton_phone:
                    intent.setAction(intent.ACTION_DIAL); // 调用拨号的面板
                    intent.setData(Uri.parse("tel:043184978981")); // 设置要拨打的号码
                    startActivity(intent);
                    break;
                case R.id.imageButton_sms:
                    intent.setAction(intent.ACTION_SENDTO); // 调用发送短信息
                    intent.setData(Uri.parse("smsto:5554")); // 设置要发送的号码
                    intent.putExtra("sms_body","welcome to android"); // 设置要发送的信息内容
                    startActivity(intent);
                    break;
            }

        }
    };
}
